package com.rt.tmpt.utils.fastdfs;

import lombok.Getter;
import org.csource.common.MyException;
import org.csource.fastdfs.*;

import java.io.IOException;

/**
 * fastdfs连接工具类
 *
 * @author xx
 * @create 2017-12-21 11:04
 **/
@Getter
public class ConfigAndConnectionServer {
    private TrackerServer trackerServer;
    private StorageServer storageServer;
    private StorageClient storageClient;
    private StorageClient1 storageClient1;

    public ConfigAndConnectionServer invoke(int flag) throws IOException, MyException {

        /**
         * 1.配置文件的初始化信息
         */
        ClientGlobal.initByProperties("fastdfs.properties");
        TrackerClient tracker = new TrackerClient();
        /**
         * 2.建立连接
         */
        trackerServer = tracker.getConnection();
        storageServer = null;
        /**
         * 如果flag=0时候，构造StorageClient对象否则构造StorageClient1
         */
        if (flag == 0) {
            storageClient = new StorageClient(trackerServer, storageServer);
        } else {
            storageClient1 = new StorageClient1(trackerServer, storageServer);
        }
        return this;
    }
}
